package com.moli.iov.alarm.service.impl;

import com.moli.iov.alarm.model.po.AlarmInfoHandlerRecord;
import com.moli.iov.alarm.remote.IAlarmInfoHandlerRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * The type Alarm info handler record service.
 * @author whl
 */
@Service
public class IAlarmInfoHandlerRecordServiceImpl  implements IAlarmInfoHandlerRecordService {

    @Autowired
    protected MongoTemplate mongoTemplate;


    @Override
    public void saveAlarmInfoHandlerRecord(AlarmInfoHandlerRecord alarmInfoHandlerRecord) {
        mongoTemplate.save(alarmInfoHandlerRecord);
    }

    @Override
    public List<AlarmInfoHandlerRecord> getAlarmInfoHandlerRecord(String alarmId) {
        Criteria criteria = new Criteria();
        criteria.and("alarmId").is(alarmId);
        Query query = new Query(criteria);
        query.with(new Sort(Sort.Direction.DESC, "createDate"));
        return mongoTemplate.find(query, AlarmInfoHandlerRecord.class);
    }


}
